Add a way to specify accumulative margins. (#344499, Nate Nielsen)
authorMatthias Clasen <mclasen@redhat.com>
Sun, 29 Apr 2007 01:14:29 +0000 (01:14 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 29 Apr 2007 01:14:29 +0000 (01:14 +0000)
2007-04-28  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtktexttag.[hc]: Add a way to specify accumulative
        margins.  (#344499, Nate Nielsen)

svn path=/trunk/; revision=17685

ChangeLog
gtk/gtktexttag.c
gtk/gtktexttag.h

index deccafd791ae4cdd064299f5dc8b725414c1e8f8..49cab2d9aa1a27e4cf26e511b35af9bd4ad68bc4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtktexttag.[hc]: Add a way to specify accumulative
+       margins.  (#344499, Nate Nielsen)
+
 2007-04-28  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkeventbox.c (gtk_event_box_realize): Fix the offsets
index c1e42ec76d07d0997d3c181ed84b4ede7cbd6886..0d7db4609ae54e3d826f87171dd7fe1313cc679c 100644 (file)
@@ -106,6 +106,9 @@ enum {
   PROP_INVISIBLE,
   PROP_PARAGRAPH_BACKGROUND,
   PROP_PARAGRAPH_BACKGROUND_GDK,
+
+  /* Behavior args */
+  PROP_ACCUMULATIVE_MARGIN,
   
   /* Whether-a-style-arg-is-set args */
   PROP_BACKGROUND_SET,
@@ -534,6 +537,25 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
                                                        GDK_TYPE_COLOR,
                                                        GTK_PARAM_READWRITE));
 
+  /**
+   * GtkTextTag:accumulative-margin:
+   *
+   * Whether the margins accumulate or override each other.
+   *
+   * When set to %TRUE the margins of this tag are added to the margins 
+   * of any other non-accumulative margins present. When set to %FALSE 
+   * the margins override one another (the default).
+   *
+   * Since: 2.12
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_ACCUMULATIVE_MARGIN,
+                                   g_param_spec_boolean ("accumulative-margin",
+                                                         P_("Margin Accumulates"),
+                                                         P_("Whether left and right margins accumulate."),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+
   /* Style props are set or not */
 
 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
@@ -1290,6 +1312,12 @@ gtk_text_tag_set_property (GObject      *object,
       }
       break;
 
+    case PROP_ACCUMULATIVE_MARGIN:
+      text_tag->accumulative_margin = g_value_get_boolean (value);
+      g_object_notify (object, "accumulative-margin");
+      size_changed = TRUE;
+      break;
+
       /* Whether the value should be used... */
 
     case PROP_BACKGROUND_SET:
@@ -1616,6 +1644,10 @@ gtk_text_tag_get_property (GObject      *object,
       g_value_set_boxed (value, tag->values->pg_bg_color);
       break;
 
+    case PROP_ACCUMULATIVE_MARGIN:
+      g_value_set_boolean (value, tag->accumulative_margin);
+      break;
+
     case PROP_BACKGROUND_SET:
       g_value_set_boolean (value, tag->bg_color_set);
       break;
@@ -2148,6 +2180,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
 {
   guint n = 0;
 
+  guint left_margin_accumulative = 0;
+  guint right_margin_accumulative = 0;
+
   g_return_if_fail (!dest->realized);
 
   while (n < n_tags)
@@ -2209,8 +2244,13 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
       if (vals->direction != GTK_TEXT_DIR_NONE)
         dest->direction = vals->direction;
 
-      if (tag->left_margin_set)
-        dest->left_margin = vals->left_margin;
+      if (tag->left_margin_set) 
+        {
+          if (tag->accumulative_margin)
+            left_margin_accumulative += vals->left_margin;
+          else
+            dest->left_margin = vals->left_margin;
+        }
 
       if (tag->indent_set)
         dest->indent = vals->indent;
@@ -2218,8 +2258,13 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
       if (tag->rise_set)
         dest->appearance.rise = vals->appearance.rise;
 
-      if (tag->right_margin_set)
-        dest->right_margin = vals->right_margin;
+      if (tag->right_margin_set) 
+        {
+          if (tag->accumulative_margin)
+            right_margin_accumulative += vals->right_margin;
+          else
+            dest->right_margin = vals->right_margin;
+        }
 
       if (tag->pixels_above_lines_set)
         dest->pixels_above_lines = vals->pixels_above_lines;
@@ -2260,6 +2305,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
 
       ++n;
     }
+
+  dest->left_margin += left_margin_accumulative;
+  dest->right_margin += right_margin_accumulative;
 }
 
 gboolean
index cfc4b8b0cc3da15a3a72571d2d13679e695a7c67..61d60d9afe70ca763d1879362bf5ad5fbc6f4908 100644 (file)
@@ -125,8 +125,11 @@ struct _GtkTextTag
   guint editable_set : 1;
   guint language_set : 1;
   guint pg_bg_color_set : 1;
+
+  /* Whether these margins accumulate or override */
+  guint accumulative_margin : 1;
+
   guint pad1 : 1;
-  guint pad2 : 1;
 };
 
 struct _GtkTextTagClass